<template>
	<view class="container">
		<view class="balance-item" v-for="(month, index) in list" :key="index">
			<view class="top-wrapper">
				<view class="month">{{month.month}}</view>
				<view class="desc">支出 ¥{{month.totalOut}} 收入 ¥{{month.totalIn}}</view>
			</view>
			<!-- 1分享获得 2购物获得 3订单退款 4提出 5提现驳回 6充值 7.消费 -->
			<view class="list" v-if="list.length > 0">
				<view class="item border-bottom" v-for="(record, i) in month.records" :key="i">
					<image src="/static/chongzhi.png" v-if="record.fromType == 6" mode="aspectFill" class="icon"></image>
					<image src="/static/xiaofei.png" v-else mode="aspectFill" class="icon"></image>
					<view class="text">
						<view class="title">{{record.fromDesc}}</view>
						<view class="time">{{record.createTime}}</view>
					</view>
					<view class="num on" v-if="record.fromType == 3 || record.fromType == 6">{{record.amountStr}}</view>
					<view class="num" v-else>{{record.amountStr}}</view>
				</view>
			</view>
		</view>
		<view class='no-data' v-if="list.length < 1 && isLoad">暂无数据</view>
		<view class='end' v-if="loadingFinsh && list.length > 0">没有更多了</view>
	</view>
</template>

<script>
	import { monthes } from '@/api/user.js'
	export default {
		data() {
			return {
				type: 1, //1:余额记录 2：积分记录
				list: [],
				isLoad: false,
				loadingFinsh: false,
				loadingShow: false,
				totalCount: 0,
				pageNum: 1,
				pageSize: 10,
			}
		},
		onLoad() {
			this.getList()
		},
		onReachBottom() {
			this.pageNum = this.pageNum + 1
			this.getList()
		},
		methods: {
			getList() {
			  const len = this.list.length
			  if (this.totalCount == len && this.isLoad) {
			    this.loadingFinsh = true,
			    this.loadingShow = false
			    return
			  }
			  this.loadingShow = true
			  const data = {
			    type: this.type,
			    pageNum: this.pageNum,
			    pageSize: this.pageSize
			  }
			  monthes(data).then(respanse => {
				const { rows, total } = respanse.result
				if (rows) {
					this.list = this.list.concat(rows)
				}
			    this.totalCount = total
			    this.isLoad = true
			    this.loadingShow = false
			  })
			}
		}
	}
</script>

<style lang="scss" scoped>
	.balance-item{
		.top-wrapper{
			padding: 31rpx 45rpx 30rpx;
			.month{
				line-height: 42rpx;
				font-size: 32rpx;
				color: #040000;
			}
			.desc{
				margin-top: 12rpx;
				line-height: 36rpx;
				font-size: 26rpx;
				color: #999999;
			}
		}
		.item{
			position: relative;
			display: flex;
			padding: 39rpx 41rpx 37rpx 36rpx;
			background-color: #fff;
			&::after{
				left: 143rpx;
			}
			.icon{
				width: 84rpx;
				height: 84rpx;
				border-radius: 50%;
				background-color: #F5F5F5;
			}
			.text{
				flex: 1;
				margin-left: 22rpx;
				padding-top: 4rpx;
				.title{
					line-height: 38rpx;
					font-size: 28rpx;
					color: #000000;
				}
				.time{
					margin-top: 12rpx;
					line-height: 36rpx;
					font-size: 26rpx;
					color: #999999;
				}
			}
			.num{
				padding-top: 4rpx;
				line-height: 38rpx;
				font-size: 33rpx;
				color: #000000;
				&.on{
					color: #ED602B;
				}
			}
		}
	}
</style>
